import 'dart:ffi';

import 'package:simulator/utils/utils.dart';
import 'package:win32/win32.dart';

class OS {
  static final OS _instance = OS._internal();
  OS._internal();
  static OS getInstance() => _instance;
  void setupLimits() {}
  void setLineBuffering() {
    ///标准输出通常是行缓冲的，也就是遇到\n或者缓冲区满时才执行IO：
    //setbuf(stdout, NULL);
    //setbuf(stderr, NULL);
  }

  void setupSignal() {
    final lpEnumFunc =
        NativeCallable<PHANDLER_ROUTINE>.isolateLocal(f, exceptionalReturn: 0);

    SetConsoleCtrlHandler(lpEnumFunc.nativeFunction, 1);
  }
}

int f(int dwCtrlType) {
  print('SetConsoleCtrlHandler');
  Utils.getInstance().exitHook();
  return 0;
}
